package string.related;

public class StringSpilt {

	public static void main(String[] args) {
		// splitComma();
		// splitNoRegx();
		// splitNoReg();

		testGetHost();

	}

	private static void testGetHost() {
		getHost("http://www.diet263.com/about.html");
		getHost("https://www.atdiet.cn/about.html");
		getHost("https://www.atdiet.cn//about.html");
		getHost("https://");
		getHost("www.atdiet.cn");
		getHost("www.diet263.com/about.html");
		getHost("diet263.com//about.html");
	}

	private static void getHost(String url) {
		String from_site = url;
		if (!from_site.isEmpty()) {
			if (from_site.startsWith("http")) {
				String[] from_site_split = from_site.split("//");
				if (from_site_split.length > 1) {
					from_site = from_site.split("//")[1];
					int indexOf = from_site.indexOf("/");
					if (indexOf > 0) {
						from_site = from_site.substring(0, from_site.indexOf("/"));
					}
				} else {
					from_site = "";
				}
			} else {
				int indexOf = from_site.indexOf("/");
				if (indexOf > 0) {
					from_site = from_site.substring(0, from_site.indexOf("/"));
				}
			}
		}

		System.out.println(url + " host = " + from_site);
	}

	private static void splitNoReg() {
		String str = "adfa.2";
		String[] ss = str.split("\\.");
		int ssLen = ss.length;
		System.out.println("ss length is " + ssLen);
		for (int i = 0; i < ssLen; i++) {
			System.out.println("ss [" + i + "] = " + ss[i] + ";");
			System.out.println("ss [" + i + "] is == \"\" --> " + ("".equals(ss[i])) + ";");
			System.out.println("ss [" + i + "] is == null --> " + (ss[i].equals(null)));
		}

	}

	private static void splitNoRegx() {
		String str = "::::#EXTM3U::";
		String[] ss = str.split("@");
		int ssLen = ss.length;
		System.out.println("ss length is " + ssLen);
		for (int i = 0; i < ssLen; i++) {
			System.out.println("ss [" + i + "] = " + ss[i] + ";");
			System.out.println("ss [" + i + "] is == \"\" --> " + ("".equals(ss[i])) + ";");
			System.out.println("ss [" + i + "] is == null --> " + (ss[i].equals(null)));
		}
	}

	private static void splitComma() {
		String str = ",adfa,afa,,,ss::,ssa::,,,,,wssssssb";
		String[] ss = str.split("ss");
		int ssLen = ss.length;
		System.out.println("ss length is " + ssLen);
		for (int i = 0; i < ssLen; i++) {
			System.out.println("ss [" + i + "] = " + ss[i] + ";");
			System.out.println("ss [" + i + "] is == \"\" --> " + ("".equals(ss[i])) + ";");
			System.out.println("ss [" + i + "] is == null --> " + (ss[i].equals(null)));
		}
	}

}
